package JTest;

import Messages.Exceptions.MessageCreationException;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

import messages.Bye;
import messages.ChatMessage;
import messages.Composing;
import messages.FileRequest;
import messages.FileResponse;
import messages.Hello;
import messages.Message;
import messages.MessagesFactory;
import messages.Presence;
import messages.Wizz;

public class TestReceptionSignaux {

	/**
	 * @param args
	 * @throws IOException 
	 */
//	 public static void main(String[] args) throws IOException, MessageCreationException {
//		// TODO Auto-generated method stub
//                int PORT_SERVER=55000;
//
//		DatagramSocket server = new DatagramSocket(PORT_SERVER);
//		
//                while(true) {
//
//                        byte[] streamByte = new byte[1500];
//                        DatagramPacket inPacket = new DatagramPacket(streamByte, streamByte.length);
//                       
//                        server.receive(inPacket);
//                        Message recvMessage = MessagesFactory.getMessage(inPacket.getData());
//                        System.out.println("Message reçu par le serveur");
//
//                        if(recvMessage != null)
//                           receivedMessage(recvMessage);              
//                }
//               
//                
//	}
//
//    private static void receivedMessage(Message recvMessage) {
//        
//        if(Hello.class.isInstance(recvMessage)) {
//            Hello h = (Hello)recvMessage;
//            System.out.println("Hello recu ("+h.getUsername()+","+h.getWaitAck()+")");
//        }
//        else if(Bye.class.isInstance(recvMessage)) {
//            Bye b = (Bye)recvMessage;
//            System.out.println("Bye recu ("+b.getUsername()+")");
//        }
//        else if(ChatMessage.class.isInstance(recvMessage))
//        {
//            ChatMessage msg = (ChatMessage) recvMessage;
//            System.out.println("ChatMessage reçu de "+msg.getUsername()+": "+msg.getMsgToSend());
//        }
//        else if(FileRequest.class.isInstance(recvMessage))
//        {
//            FileRequest req = (FileRequest) recvMessage ;
//            System.out.println("FieRequest reçu de :"+req.getUsername()+"FileID :"+req.getFileId());
//        }
//        else if(FileResponse.class.isInstance(recvMessage))
//        {
//            FileResponse res = (FileResponse) recvMessage ;
//            System.out.println("FieResponse reçu de :"+res.getUsername()+"reponse :"+res.haveAccept());
//        } 
//        else if(Wizz.class.isInstance(recvMessage))
//        {
//            Wizz wiz = (Wizz)recvMessage;
//            System.out.println("Wizz reçu de :"+wiz.getUsername());
//
//        }
//        else if(Presence.class.isInstance(recvMessage))
//        {
//            Presence pre = (Presence)recvMessage;
//            System.out.println("Notif status reçu de :"+pre.getUsername()+"Status: "+pre.getStatus());
//        }
//        else if(Composing.class.isInstance(recvMessage))
//        {
//            Composing comp = (Composing)recvMessage;
//            System.out.println("Notif ecriture reçu de :"+comp.getUsername()+"isWriting: "+comp.isIsWriting());
//        }
//    }

}
